package com.hecate.common.bid;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 黄星星
 * @date 2020-12-09
 */
public class Bid32Generator implements IBidGenerator {
    private static Map<String, SegmentGen> segmentMap = new ConcurrentHashMap();

    public Bid32Generator() {
    }

    public String generateBid(String bid) {
        SegmentGen segmentGen = this.getGenerate(bid);
        return segmentGen.generate();
    }

    public SegmentGen getGenerate(String bid) {
        SegmentGen segmentGen = (SegmentGen)segmentMap.get(bid);
        if (segmentGen == null) {
            synchronized(segmentMap) {
                segmentGen = (SegmentGen)segmentMap.get(bid);
                if (segmentGen == null) {
                    segmentGen = new SegmentGen(bid);
                    segmentMap.put(bid, segmentGen);
                }
            }
        }

        return segmentGen;
    }
}
